package com.china_tanyo.greendaolearn;

import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.china_tanyo.greendaolearn.db.*;
import com.china_tanyo.greendaolearn.entity.user;

import org.greenrobot.greendao.database.Database;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        DaoSession daoSession = MyApplication.DB.newSession();

        user u = new user(null, "sadsaddddd");

        try {
            daoSession.getUserDao().insert(u);
        }
        catch (Exception e) {
            Toast.makeText(getApplicationContext(), "插入数据失败", Toast.LENGTH_SHORT).show();
        }
        Toast.makeText(getApplicationContext(), "插入成功", Toast.LENGTH_SHORT).show();

        user getu1 = daoSession.getUserDao().load(Long.valueOf("1"));
        user getu2 = daoSession.getUserDao().load(Long.valueOf("2"));
        user getu3 = daoSession.getUserDao().load(Long.valueOf("3"));
        getu3.setName("西北牛肉");
        daoSession.getUserDao().update(getu3);
    }
}
